function Airlight = AirlightUsingPatchRecurrence(orgImage)

% Internal algorithm parameters (used in the research stage):
parameters = struct(...
    'NNsearchParams',struct(...
        'numOfNNsearchFolds',7,...
        'maxNNsFromEachFold',15,...
        'multiFoldEncouragingFactor',.95,...Encouraging finding neighbors originated from different folds, the normalized correlation score of the 2nd NN from the same fold is...
                                        ...multiplied by this factor. The third by the square of it, etc'
        'tRatiosSTDthreshold',0.02,...Used before choosing NNs based on NC, when encourageMultiFoldsNNs. First taking neighbors from all folds that meet this threshold, and then the rest.
        'estimatedNoiseLevelisSTDpercentile',struct(...
            'absoluteMinNoiseSTD',0.025,...
            'diffsAveragingWinSize',10),...
        'maxCandidates',1e6,...
        'queriesNumRangeAroundSTD',[1e2,3e4],...
        'channelSTD2consider','max',...'min','max' When pruning queries based on their STD, which color channel's STD value to take?
        'numOfNNs',9),...How many NNs should be searched for
    'pairsPruning',struct(...Portion of patches left after pruning (post NN search) according to:
        'globalRate',[30 5e3],...Global pruning rate. Vector values correspond to the multi-stage search (multiPatchQualityProcess)
        'allowed_t2Tot1_ratioRange',log([2,20]),...Only using pairs whose t2DividedByt1 lies within this range (in all channels).
        'overlapPruningPrioritizingMethod','reoccurrenceScore'),...
    'pruningThreshold',struct(...
        'minNormalizedCorrelation',.8,...Patches whose NC is larger than this value are kept in addition to pairsPruning.globalRate
        'queriesSTD',struct(...98),...0.1),...[0,1] - hard threshold. [1,100] - threshold determined as percentile of largest scale image patches STD.
            'winRelativePortion',0.1,...
            'upperPercentile',0.02,...
            'noiseLevelWeightRelative2allQueriesPercentile',0.2)),...
    'downscaledSize',struct(...
        'initial',nan,...800,...400If not 1, Downscaling the original image by this factor prior to performing the whole algorithm
        'multiScale',[300,200,150,120,100],...[316,237,178,133,100],...[0.8,100],...[300,200,150,120,100],...0.5.^(1:8),...
        'approach','minDim'),......'minDim','maxDim','averageSize'
    'tRatioCalculation','norm2Ratios',...'factorization','norm2Ratios','normalizedInnerProduct',...%S in not the inner product of patches divided by I1's norm, but rather their norms' quotient
    'airlightRecovery',struct(...
        'useAmap',false,...
        'reoccurrenceScore',struct(...
            'methodNum',4,...
            'omega4lowerBound',0.98,...
            'allowedRange',exp([-5.35,-1.6])),...exp([-1,1.5])),...
        'maxAllowedPairsOverlap',.2),...Pairs of patches used for estimating A should not overlap (in both patches) in more than maxAllowedPairsOverlap of their area.
    'patchSize',7);

maxImSize = max(size(orgImage));
if maxImSize>1500
    orgImage = imresize(orgImage,1500/maxImSize);
    display(sprintf('Downscaling image by %.2f',1500/maxImSize));
end
airlightEstimationCode
Airlight = curAirlightVectEst;